<template>
	<view class="tabbarCom">
		<!-- <view class="testShare" @click="testShare()">测试分享</view> -->
		<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
			<view :class="['tabbar-item',isShow === index? 'is-hide' : '',2 === index? 'custom-tab' : '']"
				v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path)">
				<image class="item-img" :src="item.icon_a" v-if="current == index"></image>
				<image class="item-img" :src="item.icon" v-else></image>
				<view class="item-name" :class="{'tabbarActive': current == index}" v-if="item.text">{{item.text}}
				</view>
			</view>
		</view>
		<view class="shareBtn">
			<view class="talk" @click="goTalk">
				<u--image src="/static/tabbar/6.png" shape="square" mode="aspectFill" width="84rpx" height="84rpx">
				</u--image>
			</view>
			<button class="share" open-type="share">
				<u--image src="/static/tabbar/7.png" shape="square" mode="aspectFill" width="84rpx" height="84rpx">
				</u--image>
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			current: Number,
			isShow: {
				type: [Number, String],
				default: "",
			}
		},
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
					text: '首页',
					icon: '/static/tabbar/1.png', //未选中图标
					icon_a: '/static/tabbar/11.png', //选中图片
					path: "/pages/index/index", //页面路径
				}, {
					text: '社区',
					icon: '/static/tabbar/2.png', //未选中图标
					icon_a: '/static/tabbar/22.png', //选中图片
					path: "/pages/community/community", //页面路径
				}, {
					text: '',
					icon: '/static/tabbar/5.png', //未选中图标
					icon_a: '/static/tabbar/5.png', //选中图片
					path: "/pages/discuss/discuss", //页面路径
				}, {
					text: '成长',
					icon: '/static/tabbar/3.png', //未选中图标
					icon_a: '/static/tabbar/33.png', //选中图片
					path: "/pages/growup/growup", //页面路径
				}, {
					text: '我的',
					icon: '/static/tabbar/4.png', //未选中图标
					icon_a: '/static/tabbar/44.png', //选中图片
					path: "/pages/my/my", //页面路径
				}]
			};
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},
		methods: {
			tabbarChange(path) {
				uni.switchTab({
					url: path
				})
			},
			goTalk() {
				uni.navigateTo({
					url: "/pages/custumService/custumService"
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.tabbarCom {
		.tabbarActive {
			color: #004DA1FF !important;
		}

		.tabbar {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			display: flex;
			justify-content: space-around;
			align-items: center;
			width: 100%;
			height: 100rpx;
			background-color: #ffffff;
			box-shadow: 0px -2px 4px 1px #0000000A;

			.tabbar-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				height: 100rpx;

				.item-img {
					margin-bottom: 4rpx;
					width: 40rpx;
					height: 40rpx;
				}

				.item-name {
					font-size: 22rpx;
					color: #333333FF;
					font-weight: 500;
				}
			}

			.custom-tab {
				height: 140rpx;

				.item-img {
					margin-bottom: 4rpx;
					width: 106rpx;
					height: 106rpx;
					position: relative;
					top: -10rpx;
					background-color: #fff;
					border-radius: 50%;
				}
			}
		}

		.is-hide {
			display: none !important;
		}

		.shareBtn {
			position: absolute;
			right: 20rpx;
			bottom: 150rpx;
			z-index: 99;
			padding-bottom: 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.talk {
				margin-bottom: 30rpx;
			}

			.share,
			.talk {
				background: transparent;
				box-shadow: 0px 3rpx 6rpx 1rpx rgba(0, 77, 161, 0.3);
				opacity: 1;
				border-radius: 50%;
				height: 84rpx;
				width: 84rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
